package main

import (
	"chat-room/providers"
	"chat-room/routers"
	"chat-room/websocket/acc_controllers"
	"github.com/gin-gonic/gin"
)

func main() {

	// 获取配置
	app := providers.Config.GetStringMapString("app")

	// 设置对应的模式
	if app["model"] == "release" {
		gin.SetMode(gin.ReleaseMode)
	}

	// 创建路由
	r := gin.New()
	r.Use(gin.Logger())

	// 静态资源
	r.Static("css", "./public/css")
	r.LoadHTMLGlob("./public/**/**")

	api := r.Group("api")
	routers.InitRoutersApis(api)

	socket := r.Group("socket")
	routers.InitRoutersWebsocket(socket)

	// 创建websocket master
	acc_controllers.StartWebSocket()

	// 端口监听
	if port, exist := app["port"]; exist {
		r.Run(":" + port)
	} else {
		r.Run(":8080")
	}
}
